<?php
include($folder.'/layouts/code-behind/frontend.php');
$id = (int)$_GET['id'];
$content['galleryName'] = 
	queryScalar(
		'SELECT name FROM gallery WHERE gallery.id=:id',
		array('id'=>$id));
$content['parentGallery'] = 
	queryScalar(
		'SELECT gallery_id FROM gallery WHERE gallery.id=:id',
		array('id'=>$id));
		
$menuId =
	queryScalar('
		SELECT m.id 
		FROM menu2 m 
		WHERE m.link = \'/galerialista?id='.$content['parentGallery'].'\'',
		null);
OpenTreeViewNode('trvMain', $menuId);
$_POST['trvMain']['activeNode'] = 
	$_POST['smpMain']['currentNode'] = 
		$menuId;

if (empty($_POST['isPostBack']))
{
	$count = queryScalar('
		SELECT COUNT(*)
		FROM gallery g
		WHERE 
			g.gallery_id IS NOT NULL
			AND g.name < ( SELECT gg.name FROM gallery gg WHERE gg.id = :id )
	', array('id'=>$id));
	$_POST['master_galeriak']['block'] = floor($count / $master['pageSize']);	
}
function blc_kepgaleria_select_count($id)
{
	return queryScalar('SELECT COUNT(*) FROM gallery_picture WHERE gallery_id='.$id, null);
}
function blc_kepgaleria_select($from, $itemsPerPage, $id)
{
	$data = query(
	'SELECT 
		gp.text AS text, 
		gp.picture_id AS pictureID,
		gp.gallery_id AS galleryID 
	FROM 
		gallery_picture gp 
	WHERE gallery_id = :id 
	ORDER BY number LIMIT :from,:itemsPerPage',
	array('id'=>$id,'from'=>$from,'itemsPerPage'=>$itemsPerPage));
	foreach ($data as &$item) 
	{
		$item['text'] = __($item['text']);
		$item['hyperLink'] = LinkForPictureInGallery($item['galleryID'], $item['pictureID']);
	}
	return $data;
}
$master['action'] = null;
$master['attributes'] = null;
$master['pageTitle'] = $content['galleryName'];
?>